<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
	Project		: SUMMON
	Developer	: APPropolis Inc.
	Programmer	: Mark Vincent M. Lorenzo
	(c) 2014
*/

class Restaurant_lists extends CI_Controller {

	public function __construct() {
		parent::__construct();
		ini_set('session.cookie_httponly',1); 
		ini_set('session.use_only_cookies',1);
		$this->load->library('Commons');
		$this->load->model('auth_class');
		$this->load->model('users_class');
		$this->load->model('message_class');
		$this->load->model('restaurant_class');
		$this->load->model('reservation_class');
	}	
	public function global_data()
	{
		//$this->auth_class->front_no_session();
		$strEmail = $this->session->userdata('strEmail');
		$getUserInfo = $this->users_class->get_user_info($strEmail);
		$data['intUserID'] = $getUserInfo['intUserID'];
		if($getUserInfo!=0)
		{
			$data['myID'] = $getUserInfo['intUserID'];
			// Determine if the middle name have a content or none
			if($getUserInfo['strMiddleName']!='')
			{
				$midName = $getUserInfo['strMiddleName'].' ';
			}
			else
			{
				$midName = '';
			}
			// Get Account Type
			if($getUserInfo['intAccountType']=='0')
			{
				$data['userType'] = 'Client User';
			}
			else if($getUserInfo['intAccountType']=='1')
			{
				$data['userType'] = 'Administrator';
			}
			else
			{
				$data['userType'] = 'Restaurant Owner';
			}
			$data['fullname'] = $getUserInfo['strFirstName'].' '.$midName.''.$getUserInfo['strLastName'];
		}
		else
		{
			$data['fullname'] = '';
		}
		return $data;
	}
	public function index($page=null)
	{
		$data = $this->global_data();

		if (!$page) {
			$offset = 0;
		} else {
			$offset = $page;
		}
		$data['listRestoGrid'] = $this->restaurant_class->list_resto_grid($offset, $this->commons->MAX_RESTO);
		$totalPage = $this->restaurant_class->resto_grid_total();
		
		$pageConfig = $this->commons->createPagingConfig(base_url().'restaurant_lists/page', $totalPage, $this->commons->MAX_RESTO);
		$this->pagination->initialize($pageConfig);
		$pageLinks = $this->pagination->create_links();
		
		$data['totalPage'] = $totalPage;
		$data['pageLinks'] = $pageLinks;
		
		$this->load->view('commons/header_front', $data);
		$this->load->view('restaurant_lists/commons/css');
		$this->load->view('restaurant_lists/index');
		$this->load->view('commons/js');
		$this->load->view('restaurant_lists/commons/js');
		$this->load->view('commons/footer');
	}
	public function page($page=null)
	{
		$data = $this->global_data();

		if (!$page) {
			$offset = 0;
		} else {
			$offset = $page;
		}
		$data['listRestoGrid'] = $this->restaurant_class->list_resto_grid($offset, $this->commons->MAX_RESTO);
		$totalPage = $this->restaurant_class->resto_grid_total();
		
		$pageConfig = $this->commons->createPagingConfig(base_url().'restaurant_lists/page', $totalPage, $this->commons->MAX_RESTO);
		$this->pagination->initialize($pageConfig);
		$pageLinks = $this->pagination->create_links();
		
		$data['totalPage'] = $totalPage;
		$data['pageLinks'] = $pageLinks;
		
		$this->load->view('commons/header_front', $data);
		$this->load->view('restaurant_lists/commons/css');
		$this->load->view('restaurant_lists/index');
		$this->load->view('commons/js');
		$this->load->view('restaurant_lists/commons/js');
		$this->load->view('commons/footer');
	}
}